<template>
  <!-- 合同配置 -->
  <div class="box">
    <el-card
      shadow="never"
      header="公司配置"
      class="item-background"
      style="width: 100%"
    >
      <el-form
        :model="form"
        :rules="rules"
        ref="configForm"
        label-width="auto"
        label-position="right"
      >
        <el-form-item label="简介" prop="description" style="width: 100%">
          <el-input
            v-model="form.description"
            type="textarea"
            rows="10"
            clearable
            placeholder="请输入企业简介"
          ></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input
            v-model="form.phone"
            clearable
            placeholder="请输入企业电话"
          ></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input
            v-model="form.email"
            clearable
            placeholder="请输入请输入企业邮箱"
          ></el-input>
        </el-form-item>

        <el-form-item label="地址" prop="address">
          <el-input
            v-model="form.address"
            clearable
            placeholder="请输入企业地址"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="button">
        <el-button type="primary" @click="save" :loading="isSaveing"
          >保 存</el-button
        >
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      isSaveing: false,
      //表单数据
      form: {
        description: '',//简介
        address: '',//地址
        email: '',//邮箱
        phone: '',//电话

      },
      userList: [],
      rules: {
        description: [
          { required: true, message: '请输入企业简介' }
        ],
        address: [
          { required: true, message: '请输入企业地址' }
        ],
        email: [
          { required: true, message: '请输入请输入企业邮箱' }
        ],
        phone: [
          { required: true, message: '请输入企业电话' }
        ],

      }
    }
  },
  mounted () {
    this.getCompanyConfig()
  },
  methods: {
    async getCompanyConfig () {
      let res = await this.$API.banner.getCompanyConfig.get()
      console.log(res)
      this.form = res.data[0]
    },

    //表单提交方法
    save () {
      this.$refs.configForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true
          let res = await this.$API.banner.updateCompanyConfig.post(this.form)
          this.isSaveing = false
          if (res.code == 200) {
            this.$message.success("操作成功")
          }
        }
      })
    },

  }
}
</script>

<style lang="scss" scoped>
.box {
  margin: 15px;
}
.button {
  margin-top: 50px;
  padding-left: 80px;
}
</style>